package com.frank.oj.service.admin.system.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frank.model.entity.msg.AdminSysNotice;
import com.frank.oj.common.exception.StatusFailException;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.model.vo.AdminSysNoticeVO;
import com.frank.oj.service.admin.system.AdminNoticeService;
import com.frank.oj.service.entity.msg.AdminSysNoticeEntityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author frank
 * @Date 2024/3/30
 */
@Service
public class AdminNoticeServiceImpl implements AdminNoticeService {
    @Resource
    private AdminSysNoticeEntityService adminSysNoticeEntityService;
    @Override
    public CommonResult<IPage<AdminSysNoticeVO>> getSysNotice(Integer limit, Integer currentPage, String type) {
        if (currentPage == null || currentPage < 1) currentPage = 1;
        if (limit == null || limit < 1) limit = 10;

        return CommonResult.successResponse(adminSysNoticeEntityService.getSysNotice(limit,currentPage,type));
    }

    @Override
    public void addSysNotice(AdminSysNotice adminSysNotice) throws StatusFailException {
        boolean save = adminSysNoticeEntityService.saveOrUpdate(adminSysNotice);
        if (!save){
            throw new StatusFailException("通知发布失败🙁");
        }

    }

    @Override
    public void deleteSysNotice(Long id) throws StatusFailException {
        boolean delete = adminSysNoticeEntityService.removeById(id);
        if (!delete){
            throw new StatusFailException("删除出现点问题😣");
        }
    }

    @Override
    public void updateSysNotice(AdminSysNotice adminSysNotice) throws StatusFailException {
        boolean update = adminSysNoticeEntityService.saveOrUpdate(adminSysNotice);
        if (!update){
            throw new StatusFailException("通知内容修改失败");
        }
    }
}
